package org.zhouhe.web.manage.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.zhouhe.entity.TSysUser;
import org.zhouhe.entity.User;
import org.zhouhe.model.PaginationBean;
import org.zhouhe.service.UserService;
import org.zhouhe.web.util.ParameterUtils;
import org.zhouhe.web.util.ResponseUtils;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/p")
	public ModelAndView p(ModelAndView mv, HttpServletRequest request){
		mv.setViewName("p.jsp");
		return mv;
	}
	
	@RequestMapping("/sts")
	public ModelAndView sts(ModelAndView mv, HttpServletRequest request, TSysUser user){
		mv.setViewName("user/detail2.jsp");
		return mv;
	}
	@RequestMapping("/layoutTest")
	public ModelAndView layoutTest(ModelAndView mv, HttpServletRequest request, TSysUser user){
		mv.setViewName("user/layoutTest.jsp");
		return mv;
	}
	@RequestMapping(value="/data",produces="application/json")
	public void userListData(HttpServletRequest request, HttpServletResponse response, Integer rows, Integer page, Map<String, String> params) throws Exception{
		TSysUser user = ParameterUtils.fill(request, new TSysUser());
		PaginationBean pb = userService.selectListByPage("T_SYS_USER.selectUserList", page, rows, user);
		ResponseUtils.renderJson(pb, response);
	}

	@RequestMapping("/param")
	public ModelAndView param(HttpServletRequest request, User user, String[] USER_ID, String[] uid, ArrayList<String> ids){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("p.jsp");
		User user2 = ParameterUtils.fill(request, new User());
		System.out.println(ReflectionToStringBuilder.toString(user));
		System.out.println(ReflectionToStringBuilder.toString(user2));
		return mv;
	}
	@RequestMapping("/save")
	public void save(HttpServletRequest request, User user){
//		userService.saveZ2();
		TSysUser u = userService.getUser();
		System.out.println(">>>>>>>>>>>>>>..."+u);
	}
	@RequestMapping("/delete")
	public void delete(HttpServletResponse response, String[] id, String[] name, @RequestParam("REAL_NAME")String[] realName, String[] USER_ID, String[] LOGIN_NAME, String[] REAL_NAME){
		System.out.println("delete...");
		ResponseUtils.renderJson("{success='Y'}", response);
	}
	
	public static void main(String[] args) {
		System.out.println("mains");
	}
}
